package com.hzlj.position.locate.dao;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fz.common.base.converter.QueryWrapperConverterPlus;
import com.fz.common.base.converter.RemoveWrapperPlus;
import com.fz.common.base.core.JsonUtils;
import com.fz.common.base.dto.DeleteCommonDTO;
import com.hzlj.position.locate.common.common.PositionSimpleDTO;
import com.hzlj.position.locate.common.model.ReportInspectionCorrectConfig;
import com.hzlj.position.locate.mapper.ReportInspectionCorrectConfigMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * 通信联络核查-核查-纠偏配置(ReportInspectionCorrectConfig)表操作类
 *
 * @author lifh
 * @date 2023-07-26 15:57:03
 */
@Repository
public class ReportInspectionCorrectConfigDao extends ServiceImpl<ReportInspectionCorrectConfigMapper, ReportInspectionCorrectConfig> {
    @Resource
    private ReportInspectionCorrectConfigMapper reportInspectionCorrectConfigMapper;


    public PositionSimpleDTO getCorrectPosition(String id) {
        String correctPosition = QueryWrapperConverterPlus.of(reportInspectionCorrectConfigMapper)
                .selectOneField(String.class, q -> q
                        .select(ReportInspectionCorrectConfig::getCorrectPosition)
                        .eq(ReportInspectionCorrectConfig::getId, id)
                );
        if (ObjectUtil.isEmpty(correctPosition)) {
            return null;
        }
        return JsonUtils.json2obj(correctPosition, PositionSimpleDTO.class);
    }

    /**
     * 删除数据
     *
     * @param dto 实例对象
     * @return 是否成功
     */
    public boolean deleteReportInspectionCorrectConfig(DeleteCommonDTO<String> dto) {
        return RemoveWrapperPlus.remove(this, dto);
    }

}

